// Author: Bjorn Schobben

#ifndef HIGHSCORE_H
#define HIGHSCORE_H

#include "Score.h"
#include <vector>
#include <algorithm>
#include <fstream>

// Class containing highscores of a game
class Highscore
{
public:
	//Constructors
	Highscore();
	Highscore(const Highscore& rhs);

	//Destructor
	~Highscore();
	
	//Operations on the Highscore vector
	virtual void InsertScore(const Score& score);

	// Test if score will be inserted in the highscores
	bool TestScoreInsert(const Score& score) const;

	// File oriented functions
	bool LoadFromFile(const std::string& newFilename);
	bool SaveToFile(const std::string& filename) const;

	// Save highscores to file it was opened from
	void Save() const;
	

protected:
	const std::vector<Highscore::Score>& GetScores() const;

private:
	void Clear();
	void ReadScore(std::ifstream& f, Score *score) const;
	void WriteScore(std::ofstream& f, const Score& score) const;
	
	//list of highscores
	std::vector<Score> highscores;
	std::string filename;
	//Maximum amount of scores allowed in the highscore-table
	static const unsigned int MAXSCORECOUNT = 10;
};

#endif //HIGHSCORE_H
